<template>
  <div class="MajorContainer">
    <div class="search">
      <search @input="searchMajor"></search>
    </div>
    <div class="category">
      <div class="contents">
        <div
          class="content"
          @click="check(index, item.categoryCode)"
          :class="{ activing: index === currentIndex }"
          v-for="(item, index) in baseData"
          :key="item.categoryCode"
        >
          <Icon :type="item.icon" class="Icon"></Icon>
          <span>{{ item.categoryName }}</span>
        </div>
      </div>
    </div>
    <div class="complex_sort">
      <div class="sortTitle">
        <div
          class="title"
          v-for="(item, Index) in sortTitle"
          :key="item.id"
          :class="{ checked: Index === otherIndex }"
          @click="otherCheck(Index, item.id)"
        >
          {{ item.title }}
        </div>
      </div>
      <div class="sortContent">
        <div class="sort" v-for="(item, Index) in rightTitle" :key="Index">
          <!-- <div class="top">
            {{ item.title }}
            <span>({{ item.msg.length }} 个)</span>
          </div> -->
          <template v-for="(item, index) in item">
            <router-link
              :to="'/majormain/' + item.text.substring(0, item.text.indexOf('-'))"
              :key="index"
            >
              <div class="middle">
                {{ item.text }}
                <div class="bottom">
                  <div class="time">{{ item.time }}</div>
                  <div class="tag">{{ item.tag }}</div>
                </div>
              </div>
            </router-link>
          </template>
        </div>
      </div>
    </div>
    <!-- <div class="searchBox" v-show="searchShow">
      <router-link to="/usermsg">
        <div v-for="(item, index) in majorData" :key="index">
          {{ item }}
        </div>
      </router-link>
    </div> -->
  </div>
</template>

<script>
import Icon from "@/components/Icon.vue";
import search from "@/components/Search.vue";
import { getMajorTypes, getMajorTypesList, getMajorList } from "@/api/allApi";
export default {
  name: "majorComponent",
  components: {
    Icon,
    search,
  },
  data() {
    return {
      // 数据
      baseData: [
        {
          categoryCode: 8,
          categoryName: "工学",
          icon: "icon-shezhi",
        },
        {
          categoryCode: 1,
          categoryName: "哲学",
          icon: "icon-Psychiatry",
        },
        {
          categoryCode: 2,
          categoryName: "经济学",
          icon: "icon-zizhishenpi",
        },
        {
          categoryCode: 3,
          categoryName: "法学",
          icon: "icon-gongwenbao",
        },
        {
          categoryCode: 4,
          categoryName: "教育学",
          icon: "icon-jiaoyu",
        },
        {
          categoryCode: 5,
          categoryName: "文学",
          icon: "icon-wenxue",
        },
        {
          categoryCode: 6,
          categoryName: "历史学",
          icon: "icon-wenxue",
        },
        {
          categoryCode: 7,
          categoryName: "理学",
          icon: "icon-shenghuajiancha",
        },

        {
          categoryCode: 9,
          categoryName: "农学",
          icon: "icon-baoyang",
        },
        {
          categoryCode: 10,
          categoryName: "医学",
          icon: "icon-yiliao",
        },
        {
          categoryCode: 12,
          categoryName: "管理学",
          icon: "icon-shuxie",
        },
        {
          categoryCode: 13,
          categoryName: "艺术学",
          icon: "icon-yishu",
        },
      ],
      sortTitle: [
        {
          id: 1,
          title: "计算机类",
          msg: [
            {
              text: "计算机科学与技术-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "软件工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "物联网工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "信息安全-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "数据科学与大数据技术-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "网络工程-080903",
              time: "四年",
              tag: "理工学学士",
            },
            {
              text: "虚拟现实技术-080916T",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 2,
          title: "电子信息类",
          msg: [
            {
              text: "人工智能-080717T",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "电子信息工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "通信工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "电子科学与技术-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "信息工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "电子信息科学与技术-080903",
              time: "四年",
              tag: "理工学学士",
            },
            {
              text: "电子封装技术-080916T",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 3,
          title: "自动化类",
          msg: [
            {
              text: "自动化-080717T",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "机器人工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "邮政工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "核电技术与控制工程-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "智能装备与系统-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "工业智能-080903",
              time: "四年",
              tag: "理工学学士",
            },
            {
              text: "职能工程与创意设计-080916T",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 4,
          title: "机械类",
          msg: [
            {
              text: "车辆工程-080717T",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "工业设计-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "机械工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "机械电子工程-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "智能创造工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "智能交互设计-080903",
              time: "四年",
              tag: "理工学学士",
            },
            {
              text: "仿生科学与工程-080916T",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 5,
          title: "土木类",
          msg: [
            {
              text: "土木工程-080717T",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "排水工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "智能建造-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "城市水系统工程-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "城市地下空间工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
          ],
        },
        {
          id: 6,
          title: "交通运输类",
          msg: [
            {
              text: "交通运输-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "航海技术-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "飞行技术-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "交通工程-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "轮机工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "智慧交通-080903",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 7,
          title: "建筑类",
          msg: [
            {
              text: "建筑学-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "风景园林-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "城乡规划-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "城市设计-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "历史建筑保护工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
          ],
        },
        {
          id: 8,
          title: "材料类",
          msg: [
            {
              text: "材料科学与工程-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "高分子材料与工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "金属材料工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "材料化学-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "材料物理-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "功能材料-080903",
              time: "四年",
              tag: "理工学学士",
            },
          ],
        },
        {
          id: 9,
          title: "水利类",
          msg: [
            {
              text: "水利水电工程-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "水文与水资源工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "水务工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "智慧水利-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "水利科学与工程-080910T",
              time: "四年",
              tag: "理学学士、工学学士",
            },
          ],
        },
        {
          id: 10,
          title: "轻工类",
          msg: [
            {
              text: "轻化工程-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "包装工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "印刷工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "化妆品技术与工程-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
          ],
        },
        {
          id: 11,
          title: "兵器类",
          msg: [
            {
              text: "信息对抗技术-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "武器发射工程-080902",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "武器系统与工程-080905",
              time: "四年",
              tag: "工学学士",
            },
            {
              text: "智能无人系统技术-08004K",
              time: "四年",
              tag: "理学学士、工学学士",
            },
          ],
        },
        {
          id: 12,
          title: "力学类",
          msg: [
            {
              text: "工程力学-080901",
              time: "四年",
              tag: "理学学士、工学学士",
            },
            {
              text: "理论与应用力学-080902",
              time: "四年",
              tag: "工学学士",
            },
          ],
        },
      ],
      rightTitle: [
        [
          {
            text: "计算机科学与技术-080901",
            time: "四年",
            tag: "理学学士、工学学士",
          },
          {
            text: "软件工程-080902",
            time: "四年",
            tag: "工学学士",
          },
          {
            text: "物联网工程-080905",
            time: "四年",
            tag: "工学学士",
          },
          {
            text: "信息安全-08004K",
            time: "四年",
            tag: "理学学士、工学学士",
          },
          {
            text: "数据科学与大数据技术-080910T",
            time: "四年",
            tag: "理学学士、工学学士",
          },
          {
            text: "网络工程-080903",
            time: "四年",
            tag: "理工学学士",
          },
          {
            text: "虚拟现实技术-080916T",
            time: "四年",
            tag: "理工学学士",
          },
        ],
      ],
      // majorData: [
      //   "计算机科学与技术",
      //   "电子与计算机工程",
      //   "计算金融",
      //   "信息与计算科学",
      //   "数据计算及应用",
      // ],
      searchShow: false,
      currentIndex: 0,
      otherIndex: 0,
    };
  },
  async mounted() {
    this.setHeight();
    let getMajorTypesData = await getMajorTypes();
    this.school = getMajorTypesData.data.records;
    let getMajorTypesListData = await getMajorTypesList();
    console.log(getMajorTypesListData);
    let getMajorListData = await getMajorList();
    console.log(getMajorListData);
  },
  methods: {
    setHeight() {
      let cliH = document.documentElement.clientHeight;
      let conH = document.querySelector(".MajorContainer");
      // console.log(conH);
      conH.style.height = cliH - 100 + "px";
      // console.log(conH - 200);
    },
    check(index, typesId) {
      // console.log(index);
      // console.log(typesId);
      this.currentIndex = index;
    },
    otherCheck(index, typesId) {
      this.otherIndex = index;
      // console.log(typesId);
      const filteredItems = this.sortTitle.filter(
        (items) => items.id == typesId
      );
      if (filteredItems.length > 0) {
        const { msg } = filteredItems[0];
        this.rightTitle = [msg];
      }
      // console.log(this.rightTitle);
    },
    searchMajor(keyWord) {
      // 发送请求拿数据（将keyWord传值传过去）
      console.log(keyWord);
      if (!keyWord) {
        this.searchShow = false;
      } else {
        this.searchShow = true;
      }
    },
  },
};
</script>

<style lang="less" scoped>
.MajorContainer {
  // background-color: rgb(253, 225, 225);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  // height: 90%;
}
.search {
  width: 100%;
  // height: 40px;
  // background-color: skyblue;
  // margin-top: 15px;
  // padding: 0 10px;
}
.category {
  width: 90%;
  height: 80px;
  // margin-top: 15px;
  overflow-x: auto;
  overflow-y: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  .contents {
    width: 100%;
    height: 65px;
    display: grid;
    grid-template-columns: 55px 55px 55px 55px 55px 55px 55px 55px 55px 55px 55px 55px;
    grid-template-rows: 65px;
    column-gap: 16px;
    transition: all 0.5s linear;
    .content {
      width: 52px;
      height: 65px;
      background-color: white;
      cursor: pointer;
      background: linear-gradient(
        to bottom,
        white,
        white,
        rgb(239, 248, 254),
        rgb(219, 240, 255),
        skyblue
      );
      border-radius: 5px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      font-family: "宋体";
      span {
        font-size: 12px;
        letter-spacing: 1px;
      }
    }
    .Icon {
      font-size: 24px;
    }
  }
  .contents::-webkit-scrollbar {
    display: none;
  }
  .move {
    transform: translateX(-73px);
  }
  .activing {
    border: 2px solid rgba(0, 0, 255, 0.618);
    color: blue;
  }
}
.category::-webkit-scrollbar {
  height: 1px;
}
.category::-webkit-scrollbar-track {
  background-color: white;
}
.category::-webkit-scrollbar-thumb {
  -webkit-box-shadow: inset 0 0 6px rgba(0, 0, 0, 0.4);
  background-color: skyblue;
}
.complex_sort {
  border-radius: 10px;
  width: 90%;
  flex: 0.99;
  // margin-top: 15px;
  display: block;
  overflow: hidden;
  background-color: white;
}
.sortTitle {
  width: 30%;
  height: 100%;
  // background-color: gainsboro;
  overflow: auto;
  float: left;
  .title {
    width: 100%;
    height: 40px;
    line-height: 40px;
    text-align: center;
    background-color: rgb(250, 250, 250);
    color: gray;
    font-size: 13px;
    cursor: pointer;
    font-family: "宋体";
    font-weight: 700;
  }
  .checked {
    background-color: white;
    color: black;
  }
}
.sortTitle::-webkit-scrollbar {
  display: none;
}
.sortContent {
  width: 70%;
  float: left;
  overflow: auto;
  font-size: 12px;
  background-color: white;
  height: 100%;
  font-family: "宋体";
  .sort {
    width: 100%;
    margin-bottom: 7px;
    .top {
      width: 100%;
      height: 30px;
      background-color: white;
      line-height: 30px;
      padding-left: 8px;
      font-size: 15px;
      margin-top: -2px;
      span {
        color: gray;
      }
    }
    .middle {
      width: 100%;
      height: 60%;
      line-height: 20px;
      padding-bottom: 5px;
      padding-left: 8px;
      font-size: 12px;
      font-family: "宋体";
      font-weight: 700;
    }
    .bottom {
      width: 100%;
      height: 40%;
      margin-bottom: 3px;
      padding: 6px 0;
      display: flex;
      font-size: 10px;
      border-bottom: 1px solid gainsboro;
      .time {
        width: 30px;
        height: 17px;
        line-height: 17px;
        text-align: center;
        color: rgb(0, 132, 255);
        background-color: rgba(0, 132, 255, 0.1);
        border: 1px solid rgb(0, 132, 255);
        border-radius: 2px;
      }
      .tag {
        height: 17px;
        line-height: 17px;
        text-align: center;
        color: rgb(0, 132, 255);
        background-color: rgba(0, 132, 255, 0.1);
        border: 1px solid rgb(0, 132, 255);
        border-radius: 2px;
        margin-left: 5px;
        padding-left: 2px;
        padding-right: 5px;
      }
    }
  }
}
.sortContent::-webkit-scrollbar {
  display: none;
}
// 点击搜索字体图标之后/敲下enter键之后出现的盒子
.searchBox {
  width: 90%;
  height: 500px;
  background-color: white;
  position: absolute;
  top: 67px;
  left: 18px;
  overflow: auto;
  div {
    width: 100%;
    height: 40px;
    line-height: 40px;
    padding: 0 10px;
    border-bottom: 1px solid gainsboro;
    font-family: "宋体";
    font-weight: 700;
    font-size: 14px;
  }
}
.searchBox::-webkit-scrollbar {
  display: 1px;
}
</style>
